import Vue from 'vue'
import VueRouter from 'vue-router'
// 导入登录组件
import Login from './loginOrlogupOrforget/login.js'
// 导入注册组件
import Logup from './loginOrlogupOrforget/logup.js'
// 导入忘记密码组件 
import ForgetPassword from './loginOrlogupOrforget/forgetpassword.js'
// 导入报表组件
import ReportForms from './reportforms/index.js'
// 导入账单组件
import Check from './check/index.js'
// 导入社区组件
import Community from './community/index.js'
// 导入我的组件
import Me from './me/index.js'
// 导入添加账单组件
import Add from './add/index.js'
// 导入文章管理同页面
import Run from './me/run.js'
// 导入发布文章页面
import PublishArticle from './community/publisharticle.js'
// 导入设置页
import Changeme from './me/change.js'
// 导入修改个人密码页面
import ChangePassword from './me/changepassword.js'
// 导入评论详情页面
import Show from './community/show.js'


Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  Login,
  Logup,
  ForgetPassword,

  ReportForms,
  Check,
  Community,
  Me,
  Add,
  Run,
  PublishArticle,
  Changeme,
  ChangePassword,
  Show
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  let islogin = localStorage.getItem("User-Token");
  islogin = Boolean(islogin);
  if (to.path == "/login" || to.path == '/logup' || to.path == '/forgetpassword') {
    next();
    
  } else {
    if (islogin) {
      next();
    } else { 
      next('/login'); 
    }
  }
})

export default router
